<template>
	<view class="app-container">
		<image class="logo" src="/static/logo.png" style="margin-bottom: 24rpx;"></image>
		<image class="banner" src="https://trip.chinahood.net/assets/wechaapp/images/faith-me.png" mode="widthFix"></image>
		
		<view style="width: 580rpx;display: flex;flex-direction: column;align-items: center;">
			<view class="me-top">
				<image class="avatar" :src="userInfo.avatar" mode="aspectFill" @click="openUpdateModal"></image>
				<text class="alert">点击修改</text>
				<text class="name">{{userInfo.username}}</text>
			</view>
			<view class="me-center">
				<view class="me-center-child">
					<view class="value">
						{{userInfo.score}}
					</view>
					<view class="alert">
						积分
					</view>
				</view>
				<view class="me-center-child">
					<view class="value">
						{{userInfo.level}}
					</view>
					<view class="alert">
						等级
					</view>
				</view>
			</view>
			
			<view class="bottom">
				<view class="item" v-for="(item,index) in list">
					<view class="item-row" @click="pushDetail(index+1)">
						<text class="title">{{item.title}}</text>
						<!-- :style="index==1?'color:#CCCCCC':''" -->
						<view class="right">
							<!-- <text class="checkTitle">{{item.checkTitle}}</text> -->
							<image class="arrow" src="/static/resources/arrow-right.png" mode="scaleToFill"></image>
						</view>
					</view>
					<view class="item-row-btns" v-if="index==0">
						<button class="clockBtn" @click="clock(0)">超慢跑</button>
						<button class="clockBtn" @click="clock(4)">自我训练</button>
					</view>
					<view class="item-row-btns" v-if="index==1">
						<button class="clockBtn" @click="clock(11)">领取月卡</button>
						<button class="clockBtn" @click="clock(6)">阅读打卡</button>
					</view>
					<view class="item-row-btns" v-if="index==2">
						<button class="feedBack" @click="clock(9)">意见反馈</button>	
						<!-- <button class="feedBack" open-type="feedback">意见反馈</button>	 -->
					</view>
				</view>	
			</view>
		</view>
		
	<!-- 	<view class="top">
			<view class="top-left">
				<image class="avatar" :src="userInfo.avatar" mode="aspectFill" @click="openUpdateModal"></image>
			</view>
			<view class="top-center">
				<text class="name">{{userInfo.username}}</text>
				<text class="reg-time">{{userInfo.reg_time}}</text>
				<view class="alert">点击头像修改个人信息</view>
			</view>
			<view class="top-right">
				<view class="score">学分<text>{{userInfo.score}}分</text></view>
				<view class="level">等级<text>{{userInfo.level}}</text></view>
			</view>
		</view> -->
		
	
	</view>
	<update-modal @saveUserInfo='saveUserInfo' v-show="showUpdateModal" :userInfo='userInfo'></update-modal>
	<clock-modal @close='saveClockIn' v-if="showClockModal" :type='clockType'></clock-modal>
	<!-- 领取月卡弹框提醒 -->	
	<uni-popup ref="popup" type="center" :animation="false">
		<div class="popup-background" @click="close">
			<div class="popup-content">
				<div>恭喜！</div>
				<div>若您已满足积分条件 请截屏我的页面</div>
				<div>加入“文武道FAITH ERG”公众号</div>
				<div>将截屏发送至对话框</div>
				<div>领取月卡 / 年卡</div>
				<button type="default" class="popup-btn" @click="close">关闭</button>
			</div>
		</div>
	</uni-popup>
</template>

<script>
	import updateModal from '@/components/updateModal.vue'
	import clockModal from '@/components/clockModal.vue'
	const defaultAvatarUrl = 'https://mmbiz.qpic.cn/mmbiz/icTdbqWNOwNRna42FI242Lcia07jQodd2FJGIYQfG0LAJGFxM4FbnQP6yfMxBgJ0F3YRqJCJ1aPAK2dQagdusBZg/0'
	import { getUserInfo, userLogin,updateUserInfo } from '@/api/index.js'
	import {config} from "@/utils/utils.js"
	export default {
		data() {
			return {
				clockType: 0,
				
				type: 'center',
				msgType: 'success',
				messageText: '这是一条成功提示',
				value: '',
				
				avatarUrl: defaultAvatarUrl,
				nickName: '',
				showUpdateModal: false,
				showClockModal: false,
				userInfo: {
					id:3,
					avatar: defaultAvatarUrl,
					last_login: '2024-06-23',
					level: 1,
					mobile: '',
					openid: '',
					password: '',
					reg_time: '2024-06-23',
					score: 5,
					sex: 0,
					token: '',
					username: '微信用户',
					status: 1
				},
				list: [
					{
						title: '武打卡',
						checkTitle: '浏览记录',
					},
					{
						title: '文打卡',
						checkTitle: '浏览记录',
					},
					{
						title: '我的留言',
						checkTitle: '',
					},

				]
			}
		},
		
		onLoad() {
			console.log("ni.getStorageSync(config.userInfo)===",uni.getStorageSync(config.userInfo))
			if(uni.getStorageSync(config.userInfo)) {
				this.userInfo = uni.getStorageSync(config.userInfo);
			}else {
				this.isLogin = false;
			}		
		},
		onShow() {
			//更新用户信息
			let userInfo = uni.getStorageSync(config.userInfo);
			if(userInfo.openid) {
				getUserInfo({openId: userInfo.openid}).then(res=>{
					this.userInfo = res.info;
					uni.setStorageSync(config.userInfo,this.userInfo);
				})
			}
		},
		components: {
			clockModal,
			updateModal,
		},
		methods: {
			//打开更新用户信息页
			openUpdateModal() {
				this.showUpdateModal = true;
				uni.hideTabBar();
			},
			//保存用户信息
			saveUserInfo(data) {
				uni.showTabBar();
				this.userInfo = data;
				uni.setStorageSync(config.userInfo,this.userInfo);
				this.showUpdateModal = false;
			},
			//关闭pop弹框
			close() {
				this.$refs.popup.close();
				uni.showTabBar();
			},
			
			pushDetail(index) {
				if(index==1) {
					//武打卡记录
					uni.navigateTo({
						url:'/pages/record/record?type=0'
					})
				}else if(index==2) {
					// return;
					//文打卡记录
					uni.navigateTo({
						url:'/pages/record/record?type=6'
					})
				}else if(index==3) {
					//我的留言
					uni.navigateTo({
						url:'/pages/message/message'
					})
				}
				
			},
			clock(index) {
				if(index==11) {
					// uni.showToast({
					// 	title:'功能待开放',
					// 	icon: 'none'
					// })
					// return;
					uni.hideTabBar();
					this.$refs.popup.open('top');
					return;
				}
				
				// 	//超慢跑 1 自我训练 2	
				this.clockType = index;

				//this.clockType = index==1?0:4;
				this.showClockModal = true;
				uni.hideTabBar();	
			},
			saveClockIn() {
				uni.showTabBar();
				this.showClockModal = false;
				//更新用户信息
				let userInfo = uni.getStorageSync(config.userInfo);
				getUserInfo({openId: userInfo.openid}).then(res=>{
					this.userInfo = res.info;
					uni.setStorageSync(config.userInfo,this.userInfo);
				})
			}
		},
	
	}
</script>

<style lang="scss" scoped>
	.popup-background {
		position: fixed;
		width: 100vw;
		height: 100vh;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		background-color: rgba(0, 0, 0, 0.1);
		.popup-content {
			line-height:1.6;
			border-radius: 10rpx;
			display: flex;
			flex-direction: column;
			justify-content: center;
			width:90%; 
		    height: 500rpx;
			text-align: center;
			background-color: rgba(255, 255, 255, 0.9);
		}
		.popup-btn {
			margin-top: 40rpx;
			// border: 1px solid #000000;
			width: 240rpx;
			height: 80rpx;
			line-height: 80rpx;
			// background: #06c160;
			background: rgb(6, 193, 96);
			color: #fff;
		}
	}
	.app-container {
		.banner {
			width: 630rpx;
			height: 298rpx;
		}
		.me-top {
			display: flex;
			flex-direction: column;
			// justify-content: center;
			align-items: center;
			width: 100%;
			.avatar {
				width: 98rpx;
				height: 98rpx;
				border-radius: 60rpx;
				background-color: #D5D5D5;
				margin-top: 40rpx;
			}
			
			.alert {
				margin-top: 10rpx;
				font-size: 12rpx;
				line-height: 1;
				color: #808080;	
			}
			.name {
				font-size: 36rpx;
				// width: 300rpx;
				color: #000000;
				overflow: hidden;
				text-overflow: ellipsis;
				white-space: nowrap;
				margin-top: 20rpx;
				line-height: 1;
			}
			.top-center {
				display: flex;
				flex-direction: column;
				width: calc(100% - 160rpx - 300rpx);
				
				.reg-time {
					margin-top: 16rpx;
					font-size: 22rpx;
					color: #808080;
					line-height: 1;
				}
			
				
			}
			.top-right {
				width: 260rpx;
				font-size: 24rpx;
				color: #333333;
				.score,
				.level {
					margin-top: 30rpx;
					height: 42rpx;
					line-height: 42rpx;
					display: flex;
					align-items: center;
					text {
						margin-left: 30rpx;
						font-size: 42rpx;
						color: #000000;
					}
					
				}
				
			}
		}
		.me-center {
			display: flex;
			justify-content: space-between;
			width: 100%;
			margin-top: 50rpx;
			margin-bottom: 30rpx;
			.me-center-child {
				width: 50%;
				text-align: center;
				display: flex;
				justify-content: center;
				flex-direction: column;
				color: #808080;
				.value {
					font-size:40rpx;
				}
				.alert {
					font-size: 22rpx;
					margin-top: 10rpx;
				}
			}
		}
		.bottom {
			width: 100%;
			.item {
				margin-top: 10rpx;
				margin-bottom: 20rpx;
				.item-row {
					height: 80rpx;
					&:first-child {
						height: 60rpx;
					}
					// &:last-child {
					// 	border-bottom: 1px solid #F8F8F8;
					// }
					// border-top: 1px solid #F8F8F8;
					display: flex;
					justify-content: space-between;
					align-items: center;
					.title {
						// color: #333333;
						font-size: 28rpx;
						color: #808080;
					}
					.right {
						
						.checkTitle {
							color: #CCCCCC;
							font-size: 24rpx;
						}
						.arrow {
							width: 10rpx;
							height: 16rpx;
							margin-left: 10rpx;
						}
					}
				}
				.item-row-btns {
					margin-bottom: 40rpx;
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					width: 100%;
					.feedBack{
						width: 100%;
						text-align: left;
						background: none;						
						height: 80rpx;
						line-height: 80rpx;
						border-radius: 20rpx;
						margin-left: 0;
						margin-right: 0;
						border:none;						
						font-size: 28rpx;
						padding: 0rpx;
						color: #808080;	
						&::after {
							content: none;
						}
					 }
					.clockBtn {
						color: #808080;
						font-size: 26rpx;
						width: 280rpx;
						height: 80rpx;
						line-height: 80rpx;
						border-radius: 20rpx;
						margin-left: 0;
						margin-right: 0;
						border:none;
						&::after {
							content: none;
						}
					
					}
					
				}
			}
		}
	}
	
</style>